#################
MAKEFILE      = Makefile
RM            = rm -f
CP            = cp
CC            = g++
LD            = g++
COMPFLAGS     = -I.
LDFLAGS       = 
DEPENDFLAGS   = -MM
LIBS          =
#OTHER        =	-save-temps
OTHER         =

ifndef ARITY
ARITY         = 2
endif
ARITYFLAG     = -DARITY=$(ARITY)


#################
DEMO_TARGET   = demo.exe
HUF_TARGET    = huf$(ARITY).exe

DEMO_OBJS     = version.o service.o democase.o demotype.o demomain.o
HUF_OBJS      = version.o service.o huf$(ARITY)_main.o

BASIC_HUF_SRC = huf_main.cpp
HUFN_SRC      = huf$(ARITY)_main.cpp


#################
# Target Rules
#################
.SUFFIXES :
.SUFFIXES : .h .cpp .o


huf%.o : huf%.cpp
	@echo "--- ARITY = $(ARITY) ---"
	$(RM) $@
#	$(CC) $(DEPENDFLAGS) $<
	$(CC) $(COMPFLAGS) $(ARITYFLAG) $(OTHER) -c $<

%.o : %.cpp 
	@echo "-----------------"
	$(RM) $@
#	$(CC) $(DEPENDFLAGS) $<
	$(CC) $(COMPFLAGS) $(OTHER) -c $<

#################
all:	demo create_src hufn clean_src

help:
	@echo "USAGE : "
	@echo "  TBD"

demo: 		$(DEMO_TARGET)
hufn:  		$(HUF_TARGET)
create_src:	$(HUFN_SRC)

#################
$(DEMO_TARGET):	$(DEMO_OBJS) $(LIBS) $(MAKEFILE)
		@echo "================="
		$(RM) $(DEMO_TARGET)
		$(LD) -o $(DEMO_TARGET) $(LDFLAGS) $(DEMO_OBJS) $(LIBS)
		@echo " "

$(HUF_TARGET):	$(HUF_OBJS) $(LIBS) $(MAKEFILE)
		@echo "================="
		$(RM) $(HUF_TARGET)
		$(LD) -o $(HUF_TARGET) $(LDFLAGS) $(HUF_OBJS) $(LIBS)
		@echo " "


#################
clean_src :
	@echo "::::::::::::::::::"
	$(RM) $(HUFN_SRC)
	@echo " "

clean_obj :
	$(RM) *.o

$(HUFN_SRC):	$(BASIC_HUF_SRC)
	@echo "##################"
	$(RM) $(HUFN_SRC)
	$(CP) $(BASIC_HUF_SRC) $(HUFN_SRC)
	@echo " "


#################
clean1:	clean_src         
	$(RM) $(DEMO_OBJS)
	$(RM) $(HUF_OBJS)
	$(RM) *.ii
	$(RM) *.s
	$(RM) *.o
	$(RM) core

clean2:
	$(RM) $(DEMO_TARGET) $(HUF_TARGET)
	$(RM) *.exe

clean:	clean1 clean2

clean_log:
	$(RM) log_*.txt

#################
version.o:  $(MAKEFILE) version.cpp version.h
service.o:  $(MAKEFILE) service.cpp service.h version.h
democase.o: $(MAKEFILE) democase.cpp democase.h methods.h classes.h service.h demotype.h version.h
demotype.o: $(MAKEFILE) demotype.cpp demotype.h version.h
demomain.o: $(MAKEFILE) demomain.cpp methods.h classes.h service.h democase.h demotype.h version.h
huf$(ARITY)_main.o: $(MAKEFILE) huf_main.cpp huf$(ARITY)_main.cpp methods.h classes.h service.h version.h
huf$(ARITY)_main.cpp: $(MAKEFILE) huf_main.cpp version.h

